package com.zhangtai.modules.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.EmployeeOverworkDto;
import com.zhangtai.modules.dto.EmployeeOverworkPageDto;
import com.zhangtai.modules.dto.OverworkRecordDto;
import com.zhangtai.modules.dto.SecurityDto;
import com.zhangtai.modules.entity.employee.EmployeeOverworkEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-12-07 15:29:22
 */
@Mapper
public interface EmployeeOverworkDao extends BaseMapper<EmployeeOverworkEntity> {

    @Select("<script>SELECT " +
            "t1.*" +
            "FROM " +
            " tb_employee_overwork t1 " +
            "LEFT JOIN tb_sub_employee_overwork t2 ON t1.id = t2.teo_id " +
            "<where>  t1.is_delete = 0   " +
            "<if test='oprationName!=null and oprationName!=&apos;&apos;'>and t1.opration_name = like '%${oprationName}%' </if>" +
            "</where>" +
            "</script>")
    List<EmployeeOverworkEntity> getOverWorkList(@Param(value = "oprationName") String oprationName,

                                                  Page page);


    @Select("<script>SELECT " +
            "t1.*" +
            "FROM " +
            " tb_employee_overwork t1 " +
            "LEFT JOIN tb_employee_info t2 ON t1.opration_id = t2.code " +
            "<where>  t1.is_delete = 0 and t1.satus != 1 " +
            "<if test='oprationName!=null and oprationName!=&apos;&apos;'>and t1.opration_name = like '%${oprationName}%' </if>" +
            "<if test='corpName!=null and corpName!=&apos;&apos;'>and t1.corp_name = like '%${corpName}%' </if>" +
            "<if test='orgNname!=null and orgNname!=&apos;&apos;'>and t1.org_name = like '%${orgNname}%' </if>" +
            "<if test='orgIds!=null and orgIds.size>0'> and t2.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+

            "<if test='orgIds==null or orgIds.size==0'> and (t2.unit_id = null ) </if>" +
            "</where>" +
            "</script>")
    List<EmployeeOverworkEntity> getOverWorkOneHr(@Param(value = "oprationName") String oprationName,
                                                @Param(value = "corpName" ) String corpName,
                                                @Param(value = "orgNname" ) String orgNname,
                                                 Page page,@Param(value = "orgIds") List<Long> orgIds);


    @Select("<script>SELECT " +
            "t1.*" +
            "FROM " +
            " tb_employee_overwork t1 " +
            "LEFT JOIN tb_employee_info t2 ON t1.opration_id = t2.code " +
//            left join tb_employee_info info on info.oid = l.oid
            "<where>  t1.is_delete = 0  and t2.oid=#{oid}" +
            "<if test='oprationName!=null and oprationName!=&apos;&apos;'>and t1.opration_name = like '%${oprationName}%' </if>" +
            "</where>" +
            "</script>")
    List<EmployeeOverworkEntity> getOverWorkOne(@Param(value = "oprationName") String oprationName,
                                                Page page,@Param(value = "oid") Long oid);

    @Select("<script>SELECT " +
            "t1.* ,t2.employee_name " +
            "FROM " +
            " tb_employee_overwork t1 " +
            "LEFT JOIN tb_sub_employee_overwork t2 ON t1.id = t2.teo_id " +
            "LEFT JOIN tb_employee_info t3 ON t1.opration_id = t3.code " +
            "<where>  t1.is_delete = 0  and t2.employee_id=#{code} " +
            "<if test='name!=null and name!=&apos;&apos;'>and t1.opration_name = like '%${name}%' </if>" +
            "</where>" +
            "</script>")
    List<OverworkRecordDto> getRecordOverWorkList(@Param(value = "name") String name,
                                                  Page page,@Param(value = "code") String code);

//    @Select("<script>SELECT " +
//            "t1.*" +
//            "FROM " +
//            " tb_employee_overwork t1 " +
//            "LEFT JOIN tb_sub_employee_overwork t2 ON t1.id = t2.employee_id " +
//            "<where>  t1.is_delete = 0   " +
//            "<if test='oprationName!=null and oprationName!=&apos;&apos;'>and t1.opration_name = like '%${oprationName}%' </if>" +
//            "</where>" +
//            "</script>")
//     delRecordOverWorkList();

    @Select("<script>SELECT " +
            "t1.*" +
            "FROM " +
            " tb_employee_overwork t1 " +
            "<where>  t1.is_delete = 0   " +
            "<if test='id!=null and id!=&apos;&apos;'>and t1.id = #{id} </if>" +
            "</where>" +
            "</script>")
    EmployeeOverworkEntity getOverWorkListById(@Param(value = "id") Long id);


}
